//
//  ByReleaseGoodsVC.m
//  mijifen_ios
//
//  Created by mc on 2017/11/1.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByReleaseGoodsVC.h"

// view
#import "ByViewGoodsName.h"
#import "ByViewGoodsInfo.h"
#import "ByViewGoodsCondition.h"
#import "ByViewGoodsClassify.h"

@interface ByReleaseGoodsVC ()
@property (nonatomic, strong) UIScrollView *scroll;
@property (nonatomic, strong) ByModelGoodsClassify *model;
@end

@implementation ByReleaseGoodsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发布商品";
    [self addLeftBackBarButtonItem];
    [self fetchData];
    [self createViews];

}

#pragma mark -
- (void)fetchData{
    self.model = [[ByModelGoodsClassify alloc] init];
    NSMutableArray *oneArray = [NSMutableArray array];
    for (int i = 0; i < 10; i ++) {
        ByModelGoodsClassifyCate *model = [[ByModelGoodsClassifyCate alloc] init];
        model.name = @"一级分类";
        [oneArray addObject:model];
    }
    
    NSMutableArray *secArray = [NSMutableArray array];
    for (int i = 0; i < 10; i ++) {
        ByModelGoodsClassifyCate *model = [[ByModelGoodsClassifyCate alloc] init];
        model.name = @"二级分类";
        [secArray addObject:model];
    }
    
    NSMutableArray  *thridArray = [NSMutableArray array];
    for (int i = 0; i < 10; i ++) {
        ByModelGoodsClassifyCate *model = [[ByModelGoodsClassifyCate alloc] init];
        model.name = @"笔记本";
        [thridArray addObject:model];
    }
    
    self.model.oneLevelArray = [oneArray copy];
    self.model.secondLevelArray = [secArray copy];
    self.model.thridLevelArray = [thridArray copy];
   
}

#pragma mark - getter
- (UIScrollView *)scroll{
    if (!_scroll) {
        _scroll = [[UIScrollView alloc] init];
        _scroll.backgroundColor = BY_TABLE_COLOR;
        [self.view addSubview:_scroll];
        [_scroll mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.right.equalTo(self.view.mas_right);
            if (@available(iOS 11.0, *)) {
                make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
                make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-50);
            }else{
                make.top.equalTo(self.view.mas_top);
                make.bottom.equalTo(self.view.mas_bottom).offset(-50);
            }
        }];
        _scroll.showsVerticalScrollIndicator = NO;
        _scroll.bounces = NO;
        
    }
    return _scroll;
}

#pragma mark - 创建视图
- (void)createViews{
    // 提交
    UIButton *commitButton = [[UIButton alloc] init];
    [self.view addSubview:commitButton];
    [commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        }else{
            make.bottom.equalTo(self.view.mas_bottom);
        }
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50));
        
    }];
    [commitButton setTitle:@"提交" forState:UIControlStateNormal];
    [commitButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    [commitButton setBackgroundColor:BY_THEME_COLOR];
    
    // 商品名字
    ByViewGoodsName *nameView = [[ByViewGoodsName alloc] init];
    [self.scroll addSubview:nameView];
    [nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scroll.mas_left);
        make.top.equalTo(self.scroll.mas_top);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 195 + 50 + 20 + 5 + 10));
    }];
    
    // 商品信息
    ByViewGoodsInfo *infoView = [[ByViewGoodsInfo alloc] init];
    [self.scroll addSubview:infoView];
    [infoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameView.mas_bottom).offset(10);
        make.left.equalTo(self.scroll.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 100));
    }];
    
    // 商品配送条件
    ByViewGoodsCondition *conditionView = [[ByViewGoodsCondition alloc] init];
    [self.scroll addSubview:conditionView];
    [conditionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(infoView.mas_bottom);
        make.left.equalTo(self.scroll.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 260));
    }];
    
    // 商品分类
//    ByViewGoodsClassify *classifyView = [[ByViewGoodsClassify alloc] init];
//    [self.scroll addSubview:classifyView];
//    [classifyView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(conditionView.mas_bottom);
//        make.left.equalTo(self.scroll.mas_left);
//        make.right.equalTo(self.scroll.mas_right);
//        make.bottom.equalTo(self.scroll.mas_bottom);
//    }];
//    classifyView.model = self.model;
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
